<script setup>
import MessageItem from './MessageItem.vue';

defineProps({
  messages: Array,
  currentUser: String
});

const formatTime = (timeStr) => {
  const date = new Date(timeStr);
  return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
};
</script>

<template>
    <MessageItem
        v-for="(msg, index) in messages"
        :key="index"
        :message="msg"
        :isCurrentUser="msg.sender === currentUser"
        :time="formatTime(msg.timestamp)"
    />
</template>

<style scoped>
/* 样式已在全局chat.css中定义 */
@import '@/assets/chat.css';
</style>
